<?php
/**
 * Created by PhpStorm.
 * User: minicart
 * Date: 2018/10/26
 * Time: 10:49
 */
namespace app\models;
use think\Model;

/**
 * Class ClassManagementModel
 * @package app\models
 */
class ClassManagementModel extends Model
{
    protected $table = 'edu_class_management';

    /**
     * 订单列表 分页
     * @param array $where
     * @param int $page
     * @param int $limit
     * @param string $order
     * @return array
     * @throws \think\exception\DbException
     */
    public static function pageLists($where = [], $page = 1, $limit = 5, $order = 'id desc')
    {
        $result =self::where($where)->order($order)->paginate($limit,false,['page'=>$page]);
        if(!$result->total()){
            return ['code' => 0, 'msg' => "ok", 'count' =>0, 'data' => []];
        }
        foreach ($result as $key => $value) {
            $result[$key]['status_text'] = $value->status_text;
        }
        $result = $result->toArray();
        return ['code' => 0, 'msg' => "ok", 'count' => $result['total'], 'data' => $result['data']];
    }

    /**
     * 状态
     * @param $value
     * @param $data
     * @return mixed
     */
    public function getStatusTextAttr($value, $data)
    {
        $status = [1 => "上课中", 0 => "未上课"];
        return $status[$data['status']];
    }
}
